package cn.sirun.com.fca.personal.center.presenter.impl;


import com.tencent.cloud.iov.kernel.model.BaseResponse;
import com.tencent.cloud.iov.util.rx.SimpleObserver;

import cn.sirun.com.fca.account.model.base.SubmitPhoneResponse;
import cn.sirun.com.fca.personal.center.constant.PersonalCenterActionConst;
import cn.sirun.com.fca.personal.center.loader.ChangeBindAccountLoader;
import cn.sirun.com.fca.personal.center.model.request.ChangeAccountResendRequest;
import cn.sirun.com.fca.personal.center.presenter.IChangeBindAccountPresenter;
import cn.sirun.com.fca.personal.center.presenter.PersonalCenterFlowPresenter;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.subjects.BehaviorSubject;

public class ChangeBindAccountPresenter extends PersonalCenterFlowPresenter<ChangeBindAccountLoader>
        implements IChangeBindAccountPresenter {

    private BehaviorSubject<BaseResponse> mBehaviorSubject = BehaviorSubject.create();

    @Override
    protected ChangeBindAccountLoader createLoader() {
        return new ChangeBindAccountLoader();
    }


    @Override
    public void submitBindAccount(ChangeAccountResendRequest request) {
        getLoader().submitBindAccount(request)
                .takeUntil(mBehaviorSubject)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SimpleObserver<BaseResponse<SubmitPhoneResponse>>() {

                    @Override
                    public void onNext(BaseResponse<SubmitPhoneResponse> submitPhoneResponse) {
                        super.onNext(submitPhoneResponse);
                        getActionListener().onAction
                                (PersonalCenterActionConst.ACTION_SUBMIT_BIND_ACCOUNT_RESPONSE,
                                        submitPhoneResponse);
                    }
                });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mBehaviorSubject.onComplete();
    }

}
